package com.jinzhi.jzweb.controller.modelConfig;


import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzweb.domain.BookConfigDO;
import com.jinzhi.jzweb.domain.ProductTypeDO;
import com.jinzhi.jzweb.service.BookConfigService;
import com.jinzhi.jzweb.service.ProductTypeService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 
 * <pre>
 * 书籍配置
 * </pre>
 * <small> 2024-09-18 16:03:15 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/bookConfig")
@Api(value = "书籍配置", tags = {"书籍配置"})
public class BookConfigController extends BaseController {

	private final BookConfigService bookConfigService;
	public BookConfigController(BookConfigService bookConfigService){
		this.bookConfigService = bookConfigService;
	}


	@ApiOperation(value = "页面地址", notes = "页面地址 权限：jzweb:bookConfig:bookConfig")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping()
	@RequiresPermissions("jzweb:bookConfig:bookConfig")
	String ProductType(){
	    return "jzweb/bookConfig/bookConfig";
	}



	@ApiOperation(value = "书籍配置分页列表", notes = "书籍配置分页列表")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@ResponseBody
	@PostMapping("/list")
	public Result<Page<BookConfigDO>> list(BookConfigDO bookConfigDO){

        return Result.ok(bookConfigService.bookList(bookConfigDO));
	}



	@ApiOperation(value = "新增页面地址", notes = "新增页面地址")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping("/add")
	String add(){
	    return "jzweb/bookConfig/add";
	}



	@ApiOperation(value = "详情页面地址", notes = "详情页面地址")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping("/edit/{id}")
	String edit(@PathVariable("id") Long id,Model model){
		BookConfigDO bookConfigDO = bookConfigService.selectById(id);
		model.addAttribute("bookConfigDO", bookConfigDO);
	    return "jzweb/bookConfig/edit";
	}


	@ApiOperation(value = "新增书籍配置", notes = "新增书籍配置")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@ResponseBody
	@PostMapping("/save")
	public Result<String> save(@RequestBody BookConfigDO bookConfigDO){
		bookConfigDO.setCreaterId(this.getUserId());
		bookConfigService.insert(bookConfigDO);
        return Result.ok();
	}



	@ApiOperation(value = "修改书籍配置", notes = "修改书籍配置")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@ResponseBody
	@PostMapping("/update")
	public Result<String>  update(@RequestBody BookConfigDO bookConfigDO){
		bookConfigDO.setUpdaterId(this.getUserId());
		boolean update = bookConfigService.updateById(bookConfigDO);
		return update ? Result.ok() : Result.fail();
	}



	@ApiOperation(value = "删除书籍配置", notes = "删除书籍配置")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@PostMapping( "/remove")
	@ResponseBody
	public Result<String>  remove(@RequestParam("id") Long id){
		bookConfigService.deleteById(id);
        return Result.ok();
	}



	@ApiOperation(value = "批量删除删除书籍配置", notes = "批量删除删除书籍配置")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@PostMapping( "/batchRemove")
	@ResponseBody
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		bookConfigService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
	
}
